<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<%
	String bathPath = request.getContextPath();
	pageContext.setAttribute("bathPath", bathPath);
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>通行时间组</title>
<link rel="stylesheet" href="${bathPath}/frame/layui/css/layui.css">
<link rel="stylesheet" href="${bathPath}/frame/static/css/style.css">
<link rel="icon" href="${bathPath}/frame/static/image/code.png">
<link type="text/css" rel="stylesheet" href="${bathPath}/css/page.css"/>
<script type="text/javascript" src="${bathPath}/js/jquery-1.9.1.min.js" ></script>
<script type="text/javascript" src="${bathPath}/js/ajaxSessionOut.js" ></script>
<!-- 1    css资源 -->
<link rel="stylesheet" type="text/css" href="${bathPath}/js/jquery-easyui-1.4.2/themes/default/easyui.css">
<!-- 2    图标资源 -->
<link rel="stylesheet" type="text/css" href="${bathPath}/js/jquery-easyui-1.4.2/themes/icon.css"> 
<!-- 3    EasyUI的js包 -->
<script type="text/javascript" src="${bathPath}/js/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
<!-- 4    本地语言 -->
<script type="text/javascript" src="${bathPath}/js/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
<!-- layer -->
<link type="text/css" rel="stylesheet" href="${bathPath}/js/layer/skin/layer.css"/>
<script type="text/javascript" src="${bathPath}/js/layer/layer.js" ></script>
<script src="${bathPath}/frame/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">

/* var agentsList =  eval('${timelist}');
for (var i = 0; i < agentsList.length; i++) {
	var array_element = agentsList[i];
	console.log(array_element);
} */


	
    layui.use(['form', 'layedit', 'laydate', 'element'], function () {
        var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , element = layui.element;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
       /*  form.on('submit(sub)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });
            return false;
        }); */
        
        //获取下拉框中的value
         	form.on('select', function(data){
        	  //console.log(data);done
        	  //console.log(data.elem); //得到select原始DOM对象done
        	  //console.log(data.value); //得到被选中的值done
        	  //alert( $('#timeName').val());//done @c
        	  
        	}); 
        
        
    });
//});

function getParam(){
	var param  = new Object();
	param.realName = $("#realName").val();
	param.id= $("#id").val();
    param.className=$("#cName").val();
	var json=toJSONStr(param)
		return "["+json+"]";
	}
//保存调用方法
function insert(){
	var param=$("form").serialize();
	$.ajax({
		type:"POST",
		async:false,
		dataType:"text",
		data:param,
		url:"${bathPath}/aDKPowerGroupDoor/updateByautoID.action?doorTimeItemID="+ $('#timeName').val(),
		success:function(data){
			
			layer.confirm("保存成功！", {btn: ['确定'], title: "提示",skin:"my-skin"}, function(){
				parent.layer.close(parent.layer.index);
				parent.location.reload();
				});
			}
		});
	parent.layer.close(parent.layer.index);
	}
	
//JSON对象转化为字符串(防止中文乱码)
function toJSONStr(obj){
     //判断是否是IE8
     if(navigator.appVersion.match(/8./i)=="8."){
          var answerStr = JSON.stringify(obj);   
          var o = JSON.parse(answerStr); 
          eval("var answerStr = '"+JSON.stringify(o)+"';");
          return answerStr;
     }
     return JSON.stringify(obj);
} 
</script>
</head>
<body class="body">
<form class="layui-form layui-form-pane" action="">
  <input type="hidden" id="autoID" name="autoID" value="${pGdoor.autoID}" />
    <div class="layui-form-item">
        <label class="layui-form-label">通行时间组:</label>

        <div class="layui-input-inline">
            <select type="text" class="layui-input" name="timeName" id="timeName"  lay-filter="timeName" lay-verify="required">
					     <c:forEach items="${timelist}" var="List">
					      <option value="${List.autoID}"  <c:if  test="${List.autoID  eq  '2'}"> selected="selected"</c:if>  >${List.timeName}</option>
					    </c:forEach>
            </select>
        </div>
     </div>   
   
</form>


<div class="">
        <!-- <button class="layui-btn" onclick="insert()" style="margin-left:300px; ">保存</button> -->
         <button class="layui-btn site-demo-active layui-btn-sm" data-method="offset" lay-submit="" lay-filter="sub" style="margin-left:310px;" onclick="insert()">保 存</button>
</div>
</body>
</html>